package cn.lj2;

public class DN19 {
    public static void main(String[] args) {
        DN19.Solution solution = new DN19().new Solution();
    }

    class Solution {
        public class ListNode {
          int val;
          ListNode next;
          ListNode(int x) { val = x; }
      }
        public ListNode removeNthFromEnd(ListNode head, int n) {
            ListNode pre = new ListNode(0);
            pre.next=head;
            ListNode start = pre,end = pre;
            while (n!=0){
                start = start.next;
                n--;
            }
            while (start.next!=null){
                start=start.next;
                end=end.next;
            }
            end.next=end.next.next;
            return pre.next;
        }
    }
}
